﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace HYRElectric.SystemDiagram
{
	public partial class BmpListForm : System.Windows.Forms.Form
	{
		public BmpListForm(SystemCreateForm form)
		{
			this.m_parentForm = form;
			this.InitializeComponent();
			this.InitBmpList();
		}

		public void SetSelectIndex(int index)
		{
			for (int i = 0; i < this.listView1.Items.Count; i++)
			{
				if (index == i)
				{
					this.listView1.Items[i].Focused = true;
					this.listView1.Items[i].Selected = true;
					this.listView1.Items[i].EnsureVisible();
				}
				else
				{
					this.listView1.Items[i].Selected = false;
				}
			}
		}

		private void InitBmpList()
		{
			this.listView1.LargeImageList.ImageSize = new Size(44, 36);
			this.listView1.Items.Clear();
			this.listView1.BeginUpdate();
			foreach (CellInfo cellInfo in this.m_parentForm.m_cells)
			{
				this.listView1.LargeImageList.Images.Add(cellInfo.name, cellInfo.image);
				ListViewItem listViewItem = new ListViewItem();
				listViewItem.Text = cellInfo.name;
				listViewItem.ImageKey = cellInfo.name;
				this.listView1.Items.Add(listViewItem);
			}
			this.listView1.EndUpdate();
			this.listView1.Focus();
		}

		private void BmpListForm_Deactivate(object sender, EventArgs e)
		{
			base.Hide();
		}

		private void listView1_Click(object sender, EventArgs e)
		{
			if (this.listView1.SelectedItems.Count <= 0)
			{
				return;
			}
			int index = this.listView1.SelectedItems[0].Index;
			this.m_parentForm.SetPicBox(index);
			this.m_parentForm.SetButtonEnabled();
			base.Hide();
		}

		private SystemCreateForm m_parentForm;
	}
}
